Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports AllegNet

Namespace Ex01_Init
	Friend Class Main
		Inherits Api
		Friend Shared Fps As Integer = 0
		Friend Shared FpsToShow As Integer = 0

		Public Sub WinMain()
			'Define the screen resolution
			Dim ScreenRes As ScreenResolution = ScreenResolution.Size_320_240

			'Define the gfx render mode
			Dim GfxMode As GfxModes = GfxModes.GfxDirectXWin

			'Define the render engine type
			Dim RenderingMode As RenderingModes = RenderingModes.DoubleBuffering

			'Define the screen buffer Bitmap type
			Dim BmpTyp As BmpType = BmpType.Memory

			'Initialize AllegNet
			AllegNetInit()

			'Install Keyboard
			InstallKeyboard()

			'Install Timer
			InstallTimer()

			'Install the mouse
			InstallMouse()

            'Set the application running on background if it looses the focus
			SetDisplaySwitchMode(SwitchModes.SwitchBackground)

			'Set the render mode
			SetRenderMode(RenderingMode, BmpTyp)

			'Set the colorDepth
			SetColorDepth(CDepth.Depth_32_Bits)

			'Set the Gfx Mode
			SetGfxMode(GfxMode, ScreenRes)

			'Declare a callback delegate to use with timer
			Dim cTimerFct As Cproc = New Cproc(AddressOf TimerFct)

			'Install cTimerFct to be calledback each 1000 ms (1 second)
			InstallInt(cTimerFct, 1000)

			'Initialize main loop condition
			Dim Done As Boolean = False


			'Main Loop
			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)

				'Clear the buffer
				ClearBitmap(BufferedScreen)

				'Write something to the screen
				TextOutEx(BufferedScreen, DefaultFont, "Allegnet Init example", 0, 50, MakeCol(125, 204, 255), -1)

				'Write Fps to the screen
				TextOutEx(BufferedScreen, DefaultFont, FpsToShow.ToString() & " Fps", 0, 0, MakeCol(125, 204, 255), -1)

				'Show the mouse to the screen
				ShowMouse(BufferedScreen)

				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Esc) Then
					Done = True
				End If
				Fps += 1
			Loop
			'Exit AllegNet
			UninstallAllegNet()
		End Sub

		''' <summary>
		''' Timer function
		''' </summary>
		Private Sub TimerFct()
			FpsToShow = Fps
			Fps = 0
		End Sub
	End Class
End Namespace
